﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.Web.Controllers
{
    public class UserController : BaseController
    {
        public Users userModel;
        public User_groups groupModel;
        public IUser_groupsService _user_groups { get; set; }
        public override void OnActionExecuting(ActionExecutingContext context)
        {
            base.OnActionExecuting(context);
            if (!IsUserLogin())
            {
                //跳转URL
                context.Result = Redirect("/Web/Login");
                return;
            }
            //获得登录用户信息
            userModel = GetUserInfo();
            groupModel = _user_groups.GetModel(userModel.group_id);
            if (groupModel == null)
            {
                groupModel = new User_groups();
            }
            if (userModel.birthday == null)
            {
                userModel.birthday = new DateTime(1900, 1, 1);
            }
            ViewBag.userModel = userModel;
            ViewBag.groupModel = groupModel;
        }
    }
}